package com.gadgets.busi.bm02.controller;

import com.gadgets.busi.bm02.dto.*;
import com.gadgets.busi.bm02.fegin.IMcMeterialController;
import com.gadgets.busi.bm02.pojo.MaterialDict;
import com.gadgets.framework.annotation.RoleAuthCheck;
import com.gadgets.framework.common.dto.HttpBaseResp;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.util.FeginRequestMapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-11-02
 *
 */
@RestController
@RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/bm02")
public class GadgetsBm02McFork {

    @Autowired
    private IMcMeterialController mcMeterialController;

    /**
     * 新增配方表
     * @param request                       请求信息
     * @param response                      应答信息
     * @param recipeInfoDTO                 合成表信息
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/addRecipe.do")
    public void addRecipeInfo(HttpServletRequest request, HttpServletResponse response, RecipeInfoManageDTO recipeInfoDTO) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(recipeInfoDTO, requestParam);
        mcMeterialController.addRecipeInfo(requestParam);
    }

    /**
     * 更新配方表
     * @param request                       请求信息
     * @param response                      应答信息
     * @param recipeInfoDTO                 合成表信息
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/editRecipe.do")
    public void editRecipeInfo(HttpServletRequest request, HttpServletResponse response, RecipeInfoManageDTO recipeInfoDTO) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(recipeInfoDTO, requestParam);
        mcMeterialController.editRecipeInfo(requestParam);
    }

    /**
     * 查询物品列表
     * @param request                       请求信息
     * @param response                      应答信息
     * @param queryDTO                      查询条件
     * @param pagination                    分页信息
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/dictQuery.do")
    public HttpBaseResp<MaterialDict> queryDictList(HttpServletRequest request, HttpServletResponse response, MaterialDictQueryDTO queryDTO, Pagination pagination) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(queryDTO, requestParam);
        FeginRequestMapUtil.parseRequestParam(pagination, requestParam);
        return mcMeterialController.queryDictList(requestParam);
    }

    /**
     * 查询多个物品的联合合成表
     * @param request                       请求信息
     * @param response                      应答信息
     * @param queryDTO                      查询条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/meterialCountMulti.do")
    public SumDemendsResultDTO multiCountQuery(HttpServletRequest request, HttpServletResponse response, String queryDTO) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        requestParam.put("queryDTO", queryDTO);
        return mcMeterialController.multiCountQuery(requestParam);
    }
    
    /**
     * 物品合成需求查询
     * @param request                       请求信息
     * @param response                      应答信息
     * @param recipeQueryDTO                查询条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/meterialCount.do")
    public DemendsResultDTO meterialCountQuery(HttpServletRequest request, HttpServletResponse response, RecipeQueryDTO recipeQueryDTO) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(recipeQueryDTO, requestParam);
        return mcMeterialController.meterialCountQuery(requestParam);
    }

    /**
     * 合成表Excel导出
     * @param request                       请求信息
     * @param response                      应答信息
     * @param recipeQueryDTO                合成查询信息
     * @return                              Excel文件流
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/meterialExcel.do")
    public HttpBaseResp excelExport(HttpServletRequest request, HttpServletResponse response, RecipeQueryDTO recipeQueryDTO) throws GadgetsServiceException, IOException {
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(recipeQueryDTO, requestParam);
        return mcMeterialController.excelExport(requestParam);
    }

    /**
     * 合成表Excel导出
     * @param request                       请求信息
     * @param response                      应答信息
     * @param queryDTO                合成查询信息
     * @return                              Excel文件流
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/meterialExcelMulti.do")
    public HttpBaseResp excelExportMulti(HttpServletRequest request, HttpServletResponse response, String queryDTO) throws GadgetsServiceException, IOException {
        HashMap<String, Object> requestParam = new HashMap<>();
        requestParam.put("queryDTO", queryDTO);
        return mcMeterialController.excelExportMulti(requestParam);
    }


    /**
     * 新增物品信息
     * @param materialInfo                  物品信息
     * @return                              新增结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/addMaterial.do")
    public HttpBaseResp<Object> addMaterialInfo(String materialInfo) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        requestParam.put("materialInfo", materialInfo);
        return mcMeterialController.addMaterialInfo(requestParam);
    }

    /**
     * 数据导出
     * @return                              物品信息
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/dataExpot.do")
    public HttpBaseResp<Object> dataExport() throws GadgetsServiceException{
        return mcMeterialController.dataExport();
    }

    /**
     * 生产时间计算
     * @param calDTO                    生产信息
     * @return                          耗时
     * @throws GadgetsServiceException  异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/timeCalculate.do")
    public BigDecimal productTimeCalculate(TimeCalDTO calDTO) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(calDTO, requestParam);
        return mcMeterialController.productTimeCalculate(requestParam);
    }

    /**
     * 全量更新物品拼音
     * @throws GadgetsServiceException  异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/pinyinGen.do")
    public void dictPinYinGenerator() throws GadgetsServiceException{
        mcMeterialController.dictPinYinGenerator();
    }


}
